package com.hbsoft.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.hbsoft.vo.*;
import com.hbsoft.util.*;

public class InitDateDao 
{
	private List<KindsInfoVo> kindList = null;
	private List<ColorsInfoVo> colorList = null;
	private List<PriceInfoVo> priceList = null;
	private List<SpecsInfoVo> specList = null;
	
	private DBUtil util = null;
	private SqlConfig conf = null;
	private String kindInfoSql = null;
	private String colorInfoSql = null;
	private String priceInfoSql = null;
	private String specInfoSql = null;
	
	public InitDateDao()
	{
		kindList = new ArrayList<KindsInfoVo>();
		colorList = new ArrayList<ColorsInfoVo>();
		priceList = new ArrayList<PriceInfoVo>();
		specList = new ArrayList<SpecsInfoVo>();
		
		util = DBUtil.getInstance();
		conf = SqlConfig.getInstance();
		kindInfoSql = conf.getKindInfoSql();
		colorInfoSql = conf.getColorInfoSql();
		specInfoSql = conf.getSpecInfoSql();
		priceInfoSql =conf.getPriceInfoSql();
	}
	
	public List<KindsInfoVo> getKindsInfoVoList() throws SQLException
	{
		
		Connection con = util.getConnection();
		
		PreparedStatement ps = con.prepareStatement(kindInfoSql);
		ResultSet rst = ps.executeQuery();
		while(rst.next())
		{
			KindsInfoVo kindVo = new KindsInfoVo();
			kindVo.setId(rst.getInt(1));
			kindVo.setKind(rst.getString(2));
			kindList.add(kindVo);
		}
		return kindList;
	}
	

	public List<ColorsInfoVo> getColorsInfoVoList() throws SQLException
	{
		
		Connection con = util.getConnection();
		
		PreparedStatement ps = con.prepareStatement(colorInfoSql);
		ResultSet rst = ps.executeQuery();
		while(rst.next())
		{
			ColorsInfoVo colorVo = new ColorsInfoVo();
			colorVo.setId(rst.getInt(1));
			colorVo.setColor(rst.getString(2));
			colorList.add(colorVo);
		}
		return colorList;
	}
	

	public List<PriceInfoVo> getPriceInfoVoList() throws SQLException
	{
		
		Connection con = util.getConnection();
		
		PreparedStatement ps = con.prepareStatement(priceInfoSql);
		ResultSet rst = ps.executeQuery();
		while(rst.next())
		{
			PriceInfoVo priceVo = new PriceInfoVo();
			priceVo.setId(rst.getInt(1));
			priceVo.setPrice(rst.getString(2));
			priceList.add(priceVo);
		}
		return priceList;
	}
	

	public List<SpecsInfoVo> getSpecsInfoVoList() throws SQLException
	{
		
		Connection con = util.getConnection();
		
		PreparedStatement ps = con.prepareStatement(specInfoSql);
		ResultSet rst = ps.executeQuery();
		while(rst.next())
		{
			SpecsInfoVo specVo = new SpecsInfoVo();
			specVo.setId(rst.getInt(1));
			specVo.setSpec(rst.getString(2));
			specList.add(specVo);
		}
		return specList;
	}
}
